package com.sfac.springboot.modules.account.controller;

import com.sfac.springboot.modules.account.service.UserService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * @Description AccountController
 * @Author JiangHu
 * @Date 2022/8/27 10:38
 */
@Controller
public class AccountController {

	@Autowired
	private UserService userService;

	/**
	 * 127.0.0.1/register ---- get
	 */
	@GetMapping(value = "/register")
	public String register(ModelMap modelMap) {
		modelMap.addAttribute("template",
				"account/register");
		return "index3";
	}

	/**
	 * 127.0.0.1/login ---- get
	 */
	@GetMapping(value = "/login")
	public String login(ModelMap modelMap) {
		modelMap.addAttribute("template",
				"account/login");
		return "index3";
	}

	/**
	 * 127.0.0.1/logout ----get
	 */
	@GetMapping(value = "/logout")
	public String logout(){
		userService.logout();
		return "redirect:/login";
	}

	/**
	 * 127.0.0.1/account/users ---- get
	 */
	@GetMapping(value = "/account/users")
	@RequiresRoles(value = {"admin","manager"}, logical = Logical.OR)
	public String usersPage() {
		return "index";
	}

	/**
	 * 127.0.0.1/account/roles ---- get
	 */
	@GetMapping(value = "/account/roles")
	@RequiresRoles(value = {"admin","manager"}, logical = Logical.OR)
	public String rolesPage() {
		return "index";
	}

	/**
	 * 127.0.0.1/account/resources ----get
	 */
	@GetMapping(value = "/account/resources")
	@RequiresRoles(value = {"admin","manager"}, logical = Logical.OR)
	public String resourcesPage(){
		return "index";
	}
}
